package com.hx.yupao.config;

import lombok.Data;
import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.api.RedissonReactiveClient;
import org.redisson.api.RedissonRxClient;
import org.redisson.config.Config;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Redisson配置
 */
@Configuration
@ConfigurationProperties("spring.redis")
@Data
public class RedissonConfig {

    private String host;

    private String port;

    private String password;

    @Bean
    public RedissonClient redissonClient() {
        Config config = new Config();
        //本地redis不需要密码
        String redisAddress = String.format("redis://%s:%s", host, port);
        //服务器redis需要密码
//        String redisAddress = String.format("redis://:%s@%s:%s", password, host, port);
        config.useSingleServer().setAddress(redisAddress).setDatabase(3);


        // Sync and Async API
        RedissonClient redisson = Redisson.create(config);
        return redisson;

    }
}
